package com.hujf.mapreduce.partitioner2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author Hujf
 * @title: FlowMapper
 * @date 2021/3/3017:10
 * @description: TODO
 */
public class FlowMapper extends Mapper<LongWritable, Text,Text,FlowBean> {

    private Text outK=new Text();
    private FlowBean flowBean = new FlowBean();
    
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1.获取一行
        String line = value.toString();

        String[] split = line.split("\t");

        //想要抓取的数据
        String phone = split[1];
        String up = split[split.length-3];
        String down = split[split.length-2];

        outK.set(phone);
        flowBean.setUpFlow(Long.parseLong(up));
        flowBean.setDownFlow(Long.parseLong(down));
        flowBean.setTotal();
        context.write(outK,flowBean);
    }
}
